﻿<?php
namespace Api\Controller;
use Think\Controller;

class CreditController extends Controller
{

	public function sxdj(){
		$data['Lrczy']=I('post.user');
		$token=I('token');
		$data['UPzh']=I('post.u_id');	
		$pzh=I('post.pzh');
		$data['dkSqSxMoney']=I('post.dksqsxmoney');				
		$data['jbr']=I('post.jbr');					
		$data['jbdate']=I('post.jbdate');					
		$userinfo=M('userinfo')->where(['Pzh'=>$data['UPzh']])->find();
		if ($userinfo) {
			$dksx=M('dksx');
			$row=$dksx->field('Pzh')->select();
				foreach ($row as $v) {
					if ($v['Pzh']==$pzh) {
						$pzh=date('ymdHis002',time());
						$pzh='S'.$pzh;
					}
				}
			//创建申请日期
			$lrdate=date('Y-m-d H:i:s',time());	
			$data['Pzh']=$pzh;//订单号
			$data['LrDate']=$lrdate;//申请日期
			
			$data['UName']=$userinfo['uname'];
			$data['ULxdh']=$userinfo['ulxdh'];
			$b=$dksx->add($data);//添加数据到数据库
			if ($b) {
				//写入log日志
					$admin=M('log');
					$row = array(
							
							'czLr' => $data['Lrczy'].'录入了授信申请，单号：'.$data['Pzh'],
							'CzName' => $data['Lrczy'],
							'czdate' => date('Y-m-d H:i:s',time()),
							'gs'=>'jsapp',
							'yyyy'=>'fox'
						);
					$admin->add($row);


				$this->ajaxReturn(['code'=>101,'msg'=>'申请成功']);

			}else{
				$this->ajaxReturn(['code'=>102,'msg'=>'申请失败']);
			}




		}else{

			$this->ajaxReturn(['code'=>102,'msg'=>'申请失败']);
			
		}

							
							


	}


		public function search(){
		$keyword=I('post.keyword');
		$user=I('post.user');
		$userinfo=M('userinfo');
		$login=M('login');
		$qxshow=$login->where(['CzyName'=>$user])->getField('qxshowall');
		// echo $qxshow;die;
		if ($qxshow==1) {
			if ($keyword=='') {
				$data=$userinfo->select();
			}
			$data=$userinfo->where(['UName'=>['like',"%$keyword%"]])->select();
		}else{
			$data=$userinfo->where(['UName'=>['like',"%$keyword%"],'lrczy'=>$user])->select();
			if ($keyword=='') {
				$data=$userinfo->where(['lrczy'=>$user])->select();
			}
		}
		
		$this->ajaxReturn(['code'=>101,'msg'=>'查询成功','data'=>$data]);



	}

	public function get_banben(){
		$model=M('config');
		$banben=$model->find();
		$this->ajaxReturn(['code'=>101,'msg'=>'ok','data'=>$banben['dataval']]);


	}






	
	
}


























  ?>